package com.yanqu.road.server.pb;

import com.yanqu.road.entity.config.manor.ManorWeather;
import com.yanqu.road.entity.manor.*;
import com.yanqu.road.entity.player.UserInfo;
import com.yanqu.road.logic.pb.PlayerBasePb;
import com.yanqu.road.pb.manor.ManorProto;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.manor.ManorBuildingModel;
import com.yanqu.road.server.gameplayer.module.manor.ManorGuestModel;
import com.yanqu.road.server.gameplayer.module.manor.ManorHarvestModel;
import com.yanqu.road.server.gameplayer.module.manor.ManorTechnologyModel;
import com.yanqu.road.server.manger.manor.ManorMgr;

import java.util.LinkedList;
import java.util.Map;

/**
 * @author ：zfr
 * @date ：2021/5/25 17:55
 */
public class ManorPb {
    public static ManorProto.ManorOutPutDataTemp.Builder parseManorOutPutDataTemp(ManorHarvestData harvestData) {
        ManorProto.ManorOutPutDataTemp.Builder outPutTemp = ManorProto.ManorOutPutDataTemp.newBuilder();
        outPutTemp.setId(harvestData.getOutPutId());
        outPutTemp.setLv(harvestData.getLv());
        outPutTemp.setAdditionLv(harvestData.getSpecialSkillLv());
        outPutTemp.setSkinId(harvestData.getSkinId());
        outPutTemp.setCollectTime(harvestData.getCollectTime());
        outPutTemp.setRealCollectTime(harvestData.getRealCollectTime());
        outPutTemp.setYieldStash(harvestData.getYieldStash());
        outPutTemp.setNickName(harvestData.getNickName());
        outPutTemp.setChangeNameTimes(harvestData.getChangeNameTimes());
        return outPutTemp;
    }

    public static ManorProto.ManorGuestDataTemp.Builder parseManorGuestDataTemp(ManorGuestData guestData) {
        ManorProto.ManorGuestDataTemp.Builder guestTemp = ManorProto.ManorGuestDataTemp.newBuilder();
        guestTemp.setId(guestData.getId());
        guestTemp.setSkinId(guestData.getSkinId());
        guestTemp.addAllUnLockSkinId(guestData.getSkinIdList());
        return guestTemp;
    }

    public static ManorProto.ManorBuildingDataTemp.Builder parseManorBuildingDataTemp(ManorBuildingData buildingData) {
        ManorProto.ManorBuildingDataTemp.Builder buildingTemp = ManorProto.ManorBuildingDataTemp.newBuilder();
        buildingTemp.setId(buildingData.getId());
        buildingTemp.setSkinId(buildingData.getSkinId());
        return buildingTemp;
    }

    public static ManorProto.ManorTechnologyDataTemp.Builder parseManorTechnologyDataTemp(ManorTechnologyData technologyData) {
        ManorProto.ManorTechnologyDataTemp.Builder technologyTemp = ManorProto.ManorTechnologyDataTemp.newBuilder();
        technologyTemp.setId(technologyData.getId());
        technologyTemp.addAllSkillLv(technologyData.getSkillLvList());
        return technologyTemp;
    }

    public static ManorProto.ManorVisitOtherRespMsg.Builder getManorVisitOtherRespMsg(UserManorData userManorData, Map<Integer, ManorHarvestData> harvestDataMap, Map<Integer, ManorGuestData> guestDataMap, Map<Integer, ManorBuildingData> buildingDataMap, UserInfo userInfo) {
        ManorProto.ManorVisitOtherRespMsg.Builder respMsg = ManorProto.ManorVisitOtherRespMsg.newBuilder();
        respMsg.setProsperousValue(userManorData.getProsperousValue());
        respMsg.setFarmPartUnLock(userManorData.getFarmLandUnLock());
        for (ManorHarvestData harvestData : harvestDataMap.values()) {
            respMsg.addOutPutData(parseManorOutPutDataTemp(harvestData));
        }

        for (ManorGuestData guestData : guestDataMap.values()) {
            respMsg.addGuest(parseManorGuestDataTemp(guestData));
        }

        for (ManorBuildingData buildingData : buildingDataMap.values()) {
            respMsg.addBuilding(parseManorBuildingDataTemp(buildingData));
        }
        respMsg.setHelpCount(userInfo.getManorHelpCount());
        respMsg.setRet(0);
        return respMsg;
    }

    public static ManorProto.ManorDataMsg.Builder getManorDataMsg(UserManorData userManorData, ManorHarvestModel harvestModel, ManorGuestModel guestModel, ManorBuildingModel buildingModel, ManorTechnologyModel technologyModel, GamePlayer player) {
        ManorProto.ManorDataMsg.Builder respMsg = ManorProto.ManorDataMsg.newBuilder();
        respMsg.setProsperousValue(userManorData.getProsperousValue());
        respMsg.setFarmPartUnLock(userManorData.getFarmLandUnLock());
        respMsg.setNpcEventId(userManorData.getEventId());
        respMsg.setGetReward(userManorData.isGetReward());
        for (ManorHarvestData harvestData : harvestModel.getHarvestDataMap().values()) {
            respMsg.addOutPutData(parseManorOutPutDataTemp(harvestData));
        }

        for (ManorGuestData guestData : guestModel.getGuestDataMap().values()) {
            respMsg.addGuest(parseManorGuestDataTemp(guestData));
        }

        for (ManorBuildingData buildingData : buildingModel.getBuildingDataMap().values()) {
            respMsg.addBuilding(parseManorBuildingDataTemp(buildingData));
        }

        for (ManorTechnologyData technologyData : technologyModel.getTechnologyDataMap().values()) {
            respMsg.addTechnologyData(parseManorTechnologyDataTemp(technologyData));
        }
        respMsg.setHelpCount(player.getUserInfo().getManorHelpCount());
        ManorWeather manorWeather = ManorMgr.getManorWeatherList().get(0);
        respMsg.setWeather(manorWeather.getWeather());
        respMsg.setCurWeatherEndTime(manorWeather.getEndTime());
        return respMsg;
    }

    public static ManorProto.NoticeManorHelpMsg.Builder parseNoticeManorHelpMsg(ManorHelpRecord manorHelpRecord) {
        ManorProto.NoticeManorHelpMsg.Builder respMsg = ManorProto.NoticeManorHelpMsg.newBuilder();
        respMsg.setRecord(parseManorHelpRecordTempMsg(manorHelpRecord));
        return respMsg;
    }

    public static ManorProto.ManorHelpRecordTempMsg.Builder parseManorHelpRecordTempMsg(ManorHelpRecord manorHelpRecord) {
        ManorProto.ManorHelpRecordTempMsg.Builder respMsg = ManorProto.ManorHelpRecordTempMsg.newBuilder();
        respMsg.setRecordUid(manorHelpRecord.getRecordUid());
        respMsg.setOperateUserId(manorHelpRecord.getOperateUserId());
        respMsg.setPlayerBaseData(PlayerBasePb.parsePlayerBaseTempMsg(manorHelpRecord.getOperateBaseInfo()));
        respMsg.setRecordTime(manorHelpRecord.getRecordTime());
        return respMsg;
    }


    public static ManorProto.GetManorHelpRecordListRespMsg.Builder parseManorHelpRecordListMsg(LinkedList<ManorHelpRecord> manorHelpRecordList) {
        ManorProto.GetManorHelpRecordListRespMsg.Builder respMsg = ManorProto.GetManorHelpRecordListRespMsg.newBuilder();
        for (ManorHelpRecord record : manorHelpRecordList) {
            respMsg.addRecord(parseManorHelpRecordTempMsg(record));
        }
        return respMsg;
    }


}
